home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / osi / isode / dosisode / DOSISODE80.ZIP / ISODE8.WRK / UNIX / LIB / WRITEV.C < prev   
Encoding:
C/C++ Source or Header  |  1992-02-20  |  1.1 KB  |  47 lines

  1. #include <sys/types.h>
  2. #include <sys/uio.h>
  3.  
  4. int writev(s,iov,iovcnt)
  5. int s;
  6. struct iovec *iov;
  7. int iovcnt;
  8. {
  9.     int cnt, cc, i, j, bufflen, iovlen;
  10.     char buffer[1024];
  11.     char *ptr;
  12.  
  13.     cnt = 0;     /* total character count */
  14.     j = 0;    /* index into the iov entries  */
  15.     i = 0;  bufflen = 512;
  16.     ptr = iov[j].iov_base;
  17.     iovlen = iov[j].iov_len;
  18.  
  19.     while (j < iovcnt) {    /* do all the iov blocks   */
  20.         if (bufflen < iovlen) cc = bufflen;
  21.         else  cc = iovlen;
  22.         bcopy(ptr, buffer+i, cc);  /* copy from iov to buffer */
  23.         ptr += cc;        /*  increment everything  */
  24.         i += cc;
  25.         iovlen -= cc;
  26.         bufflen -= cc;
  27.         if (i >= 512){    /* if buffer is full--flush   */
  28.             cnt += si_write(s, buffer, i);
  29.             i=0;     /* reinitialize variables  */
  30.             bufflen = 512;
  31.         }
  32.         if (iovlen <= 0){  /* if iov block is done...get next one */
  33.             j += 1;
  34.             if (j < iovcnt){
  35.                 ptr = iov[j].iov_base;
  36.                 iovlen = iov[j].iov_len;
  37.             }
  38.         }
  39.     }
  40.     if (bufflen != 512){    /* output any partial buffer  */
  41.         cnt += si_write(s, buffer, i);
  42.     }
  43.     return(cnt);    /* return total character count  */
  44. }
  45.  
  46.  
  47.